package p2pcdnsim.network;

import p2pcdnsim.exception.LinkAlreadyInsertedException;
import p2pcdnsim.exception.NodeAlreadyInsertedException;
import p2pcdnsim.exception.NodeUnexistentException;
import desmoj.core.simulator.Model;

public class TopologyConstructor {
	Model model;
	private NetworkTopologyBuilder builder;
	
	
	public void setModel(Model model) {
		this.model = model;
	}
	
	public void setBuilder(NetworkTopologyBuilder builder) {
		this.builder = builder;
	}
	
	public NetworkTopology getNetworkTopology() {
		return builder.getNetworkTopology();
	}
	
	public void constructTopology() throws NodeAlreadyInsertedException, NodeUnexistentException, LinkAlreadyInsertedException {
		builder.createNewTopology(model);
		System.out.println("Topology: create nodes.");
		builder.createNodes();
		System.out.println("Topology: create link between nodes.");
		builder.createLinks();
		System.out.println("Topology: build network stack.");
		builder.buildNetworkStack();
		System.out.println("Topology: attribute node addresses.");
		builder.attributeNodeAddresses();
		System.out.println("Topology: assign router tables.");
		builder.assignRouterTables();
		builder.createBus();
	}
}
